<%@ page import="java.util.ArrayList, modele.Sport" %>
<%
	ArrayList<Sport> sports = (ArrayList<Sport>)request.getAttribute("sports");
	Article article = (Article)request.getAttribute("article");
%>

<%
String erreur = (String)request.getAttribute("erreur");

if(erreur != null && !erreur.equals("")){
%>
<%@page import="modele.Article"%>
<div class="erreur">
	<%=erreur %>
</div>
<% 
}
%>
<div id="redactionArticle">
	
	<form id="formRedactionArticle" action="FormAction?action=publication" method="post">
		<p><label for="titreArticle">Titre de l'article :</label><textarea rows="1" cols="112" id="titreArticle" name="titreArticle"><%=article.getTitre() %></textarea></p>
		<p class="descriptionArticle">
			<label for="sportArticle">Sport :</label>
			<select id="sportArticle" name="sportArticle">
				<option value="0">choisissez un sport</option>
			<%
			for(Sport s : sports){
				long idSport = s.getId();
			%>
				<option value="<%=idSport%>" <%if(idSport == article.getSport().getId()) out.print("selected");%>><%=s.getName()%></option>
			<%
			}
			%> 
			</select>
			<label for="competitionsArticle">Competition :</label>
			<select id="competitionsArticle" class="classCompetitionsArticle" name="competitionsArticle">
				<option value="0">choisissez une competition</option>
				<option value="-1">aucune competition</option>
			</select>
			<input type="hidden" id="test" name="test" value="test"/>
		</p>
		<p>Rediger voitre article : </p>
		<div id="editor"></div>	
		<input type="hidden" id="article" name="article" />
		<input type="submit" value="publier" />
	</form>
</div>
<script type="text/javascript">
	$(document).ready(function(){
	
		
		$(window).load(function(){
 			document.getElementById("simpleEditor").contentWindow.document.body.innerHTML='tah tah';
		});
		
		$('#formRedactionArticle').submit(function () {
			$('#article').val($('#editor').simpleEditor.content());
		});
		
		$('#sportArticle').change(function() {
			
			$('#competitionsArticle').replaceWith("<img id='competitionsArticle' src='theme/ajax-loader.gif' />");
	        var id = $('#sportArticle').val(); 
	        
	        $.get(
	                'Ressources?ressource=listeCompetition',
	                {idSport: id},
	                function(data) {
	                	//alert(data);
	                	$('#competitionsArticle').replaceWith(data);
	                }
	        );

		});
	});
</script>